﻿
	function formatDate(format) {
		var date = {
			"M+" : this.getMonth() + 1,
			"d+" : this.getDate(),
			"h+" : this.getHours(),
			"m+" : this.getMinutes(),
			"s+" : this.getSeconds(),
			"q+" : Math.floor((this.getMonth() + 3) / 3),
			"S+" : this.getMilliseconds()
		};
		if (/(y+)/i.test(format)) {
			format = format.replace(RegExp.$1, (this.getFullYear() + '')
					.substr(4 - RegExp.$1.length));
		}
		for ( var k in date) {
			if (new RegExp("(" + k + ")").test(format)) {
				format = format.replace(RegExp.$1,
						RegExp.$1.length == 1 ? date[k] : ("00" + date[k])
								.substr(("" + date[k]).length));
			}
		}
		return format;
	}
	function formatMoneybeforePoint (num) {
		if(/(\-|\+)[^0-9\.]/.test(num))
			return "0";
		if(num == null || num == "")
			return "0";
		var a = num.split(".");
		if (a.length>1 && (a[1]!="" || a[1] !=null)){
			return (a[0] + '').replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,')+"."+a[1];
		}else {
			return (a[0] + '').replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,')
		}
		//alert((a[0] + '').replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,')+"."+a[1]);

	}
	function formatMoney(s,type) {
		if(/(\-|\+)[^0-9\.]/.test(s))
			return "0";
		if(s == null || s == "")
			return "0";

		var prefix = "";
		//s = s/10000;
		if(s >= 1000 || s <= -1000){
			if(s <= -1000) {
				prefix = "-";
				s = s.toString().substring(1);
			}
			s = s.toString().replace(/^(\d*)$/,"$1.");
			s = (s + "00").replace(/(\d*\.\d\d)\d*/,"$1");
			s = s.replace(".",",");
			var re = /(\d)(\d{3},)/;
			while (re.test(s)) {
				s = s.replace(re,"$1,$2");
			}
			s = s.replace(/,(\d\d)$/,".$1");
			if(type == 0){
				var a = s.split(".");
				if(a[1] == "00"){
					s = a[0];
				}
			}
		}
		return prefix + s;
	}

	function getDateStrYmd(date){
		var dd = new Date(date);
		var y = dd.getFullYear();
		var m = dd.getMonth()+1;
		var d = dd.getDate();
		return y + "-" + m + "-" + d;
	}

	function getViewMobile(mobile){
		return mobile.substring(0,3)+"****"+mobile.substring(7,11);
	}
	function getViewSendMobile(mobile){
		return mobile.substring(0,3)+"****"+mobile.substring(7,11);
	}
	//发送验证码时添加cookie
	function addCookie(name,value,expiresHours){
		var cookieString=name + "=" + value;
		//判断是否设置过期时间,0代表关闭浏览器时失效
		if(expiresHours>0){
			var date=new Date();
			date.setTime(date.getTime()+expiresHours*1000);
			cookieString=cookieString+";expires=" + date.toUTCString();
		}
		document.cookie=cookieString;
	}
	//修改cookie的值
	function editCookie(name,value,expiresHours){
		var cookieString=name + "=" + value;
		if(expiresHours>0){
			var date=new Date();
			date.setTime(date.getTime()+expiresHours*1000); //单位是毫秒
			cookieString=cookieString+";expires=" + date.toGMTString();
		}
		document.cookie=cookieString;
	}
	//根据名字获取cookie的值
	function getCookieValue(name){
		var strCookie=document.cookie;
		var arrCookie=strCookie.split("; ");
		for(var i=0;i<arrCookie.length;i++){
			var arr=arrCookie[i].split("=");
			if(arr[0]==name){
				return arr[1];
				break;
			}else{
				return "";
				break;
			}
		}

	}
	//开始倒计时
	var countdown;
	function settime(obj,name) {
		countdown=getCookieValue(name);
		if (countdown == 0) {
			obj.removeAttr("disabled");
			obj.val("获取短信验证码");
			return;
		} else {
			obj.attr("disabled", true);
			obj.val("重新发送(" + countdown + "s)");
			countdown--;
			editCookie(name,countdown,countdown+1);
		}
		setTimeout(function() { settime(obj,name) },1000) //每1000毫秒执行一次
	}

	function IdentityCodeValid(code) {
		var city={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江 ",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北 ",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏 ",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外 "};
		var tip = "";
		var pass= true;
		//兼容15位的正则，以后如果有需要再更改
		//var regIdCard=/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])((\d{4})|\d{3}[Xx])$)$/;
		if(!code || !/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i.test(code)){
			tip = "身份证号格式错误";
			pass = false;
		}

		else if(!city[code.substr(0,2)]){
			tip = "地址编码错误";
			pass = false;
		}
		else{
			//18位身份证需要验证最后一位校验位
			if(code.length == 18){
				code = code.split('');
				//∑(ai×Wi)(mod 11)
				//加权因子
				var factor = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ];
				//校验位
				var parity = [ 1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2 ];
				var sum = 0;
				var ai = 0;
				var wi = 0;
				for (var i = 0; i < 17; i++)
				{
					ai = code[i];
					wi = factor[i];
					sum += ai * wi;
				}
				var last = parity[sum % 11];
				if(parity[sum % 11] != code[17]){
					tip = "校验位错误";
					pass =false;
				}
			}
		}
		//if(!pass) alert(tip);
		return pass;
	}

	function getDynamicCode(mobile){
		if (mobile) {
			$("#alertMsg").text("请输入手机号码");
			$('#myModal').modal('show');
			return false;
		}

		var mobileReg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
		if (!mobileReg.test(mobile)){
			$("#alertMsg").text("请输入有效的手机号码");
			$('#myModal').modal('show');
			return false;
		}

		$.ajax({
			type: "GET",
			url: "/getDynamicCode.do",
			data: {
				phone: mobile,
				time:new Date().getTime()
			},
			dataType: "json",
			success: function(data){
				if(data.code == 200){
					addCookie("mobileTm",60,60);//添加cookie记录,有效时间60s
					settime($("#codeBtn"),"mobileTm");//开始倒计时
				}else{
					$("#alertMsg").text(data.result.toString());
					$('#myModal').modal('show');
					return false;
				}
			}
		});
	}

	function getNewToken(token_kv,token_param) {
		$.ajax({
			type: "POST",
			url: "/getNewToken.do",
			dataType: "json",
			success: function (data) {
				if (data.code == 200) {
					token_kv.attr("name", data.result.tokenKeyValue);
					token_kv.val(data.result.tokenParam);
					token_param.val(data.result.tokenKeyValue);
				}
			}
		});
	}

	function fomatViewNumber(num,type){
		if(num.length > type){
			var starNum = num.length - type;
			var endStr = num.substr(starNum);
			var str="";
			for(var i=0;i<starNum;i++){
				str+="*";
			}
			str = str + endStr;
			return str;
		}else{
			return num;
		}
	}

	//用于全局页面异常提示
	function alertMsgGlobalPage(data,obj) {
		if (typeof (data) == "string")
			data = eval("data=" + data);
		$("#ajump").hide();
		if (data.code == "10503") {
			var loginStr = "";
			if (data.jumpUrl != undefined && data.jumpUrl != "") {
				loginStr = "<a  id='ajump' href='/loginForm.do' class='forget-pwd' style='color: red;font-size: small;display: none'>去登录</a>";
			}
			$(obj).html(data.result.toString() + loginStr);
			return false;
		} else if (data.code == "40301") {
			$(obj).html("角色权限不够，无法操作!");
			return false;
		} else if (data.code == "40302") {
			$(obj).html("未开通相应业务，请联系客服进行开通!");
			return false;
		} else if (data.code == "40303") {
			$(obj).html("角色未开通相应操作权限，无法操作!");
			return false;
		} else {
			$(obj).html(data.result.toString());
			return false;
		}
	}

	//用于全局页面错误提示
	function alertErrorMsgGlobalPage(obj) {
		$(obj).html("服务繁忙,请稍后重试!");
		return false;
	}

	/**
	 * 验证yyyyMMdd格式的日期是否存在
	 * @param strDate
	 * @returns {boolean}
     */
	function validateDateStr(strDate){
		strDate = strDate.substring(0,4)+"-"+strDate.substring(4,6)+"-"+strDate.substring(6,8);
		var reg = /^(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)$/;
		if(reg.test(strDate))
			return true;
		else
			return false;
	}

	/**
	 * yyyy-MM-dd格式的日期月份加减
	 * @param sDate
	 * @param num
	 * @returns {string}
     */
	function addMonth(sDate, num) {

		var aYmd = sDate.split('-');
		var dt = new Date(aYmd[0], aYmd[1], aYmd[2]);

		dt.setMonth(dt.getMonth() + num);

		var y = dt.getFullYear();
		var m = dt.getMonth();
		var d = dt.getDate();
		//坑爹啊，月份是从0开始啊！！！！
		if (m == 0) { m = 12; y = y - 1; }

		if (m < 10) m = '0' + m;
		if (d < 10) d = '0' + d;
		return y + '-' + m + '-' + d;
	}

	/**
	 * yyyy-MM-dd格式的日期天数加减
	 * @param sDate
	 * @param num
	 * @returns {string}
     */
	function addDay(sDate, num) {

		var aYmd = sDate.split('-');
		var dt = new Date(aYmd[0], aYmd[1], aYmd[2]);

		dt.setDate(dt.getDate() + num);

		var y = dt.getFullYear();
		var m = dt.getMonth();
		var d = dt.getDate();

		if (m == 0) { m = 12; y = y - 1; }

		if (m < 10) m = '0' + m;
		if (d < 10) d = '0' + d;
		return y + '-' + m + '-' + d;
	}

	/**
	 * 计算天数差的函数
	 * @param sDate1
	 * @param sDate2
	 * @returns {Number|*}
     * @constructor
     */
	function  dateDiff(sDate1,  sDate2){    //sDate1和sDate2是2006-12-18格式
		var  aDate,  oDate1,  oDate2,  iDays;
		//此种写法不兼容firefox
		//aDate  =  sDate1.split("-");
		//oDate1  =  new  Date(aDate[1]  +  '-'  +  aDate[2]  +  '-'  +  aDate[0]);  //转换为12-18-2006格式
		//aDate  =  sDate2.split("-");
		//oDate2  =  new  Date(aDate[1]  +  '-'  +  aDate[2]  +  '-'  +  aDate[0]);
		aDate  =  sDate1.split("-");
		oDate1  =  new  Date(aDate[0],aDate[1]-1,aDate[2],"","","");  //转换为12-18-2006格式
		aDate  =  sDate2.split("-");
		oDate2  =  new  Date(aDate[0],aDate[1]-1,aDate[2],"","","");
		iDays  =  parseInt(Math.abs(oDate1  -  oDate2)  /  1000  /  60  /  60  /24);   //把相差的毫秒数转换为天数
		return  iDays;
	}

	/**
	 * 获取当前日期
	 * @returns {string} yyyy-MM-dd
     */
	function getNowFormatDate() {
		var date = new Date();
		var seperator1 = "-";
		var year = date.getFullYear();
		var month = date.getMonth() + 1;
		var strDate = date.getDate();
		if (month >= 1 && month <= 9) {
			month = "0" + month;
		}
		if (strDate >= 0 && strDate <= 9) {
			strDate = "0" + strDate;
		}
		var currentdate = year + seperator1 + month + seperator1 + strDate;
		return currentdate;
	}

	/**
	 * 电票背书计算每张票据实收金额
	 * @param expireDt 到期日
	 * @param intRate 年利率
     * @param amt 票面金额
     */
	function calculatePaidAmtOnRecite(expireDt,intRate,amt){
		var nowDt = getNowFormatDate();
		amt = amt.replace(/,/g,"");
		intRate = intRate.replace(/,/g,"");
		var day = dateDiff(nowDt,expireDt);
		var interest = amt * day * intRate / 360 / 100;
		return amt - interest.toFixed(2);
	}

	//判断是否为空
	function isSpace (val) {
		if ($.trim(val).length > 0)
			return false;
		else
			return true;
	}

	/**
	 * 金额的千分位展示与数字展示的相互转换
	 * @param obj
	 */
	function formatInputAmount(obj,type){
		var value = $(obj).val();
		if(!isSpace(value)){
			if(type == 0){
				$(obj).val(value.replace(/,/g,""));
			}else{
				$(obj).val(formatMoney(value,2));
			}
		}
	}
	/**
	 * 金额的千分位展示与数字展示的相互转换
	 * @param obj
     */
	function formatInputAmount(obj){
		var value = $(obj).val();
		var isFocus=$(obj).is(":focus");
		if(!isSpace(value)){
			if(true==isFocus){
				$(obj).val(value.replace(/,/g,""));
			}else{
				value = value.replace(/,/g,"");
				$(obj).val(formatMoney(value,2));
			}
		}
	}

	/**
	 * 获得焦点去掉千分位展示
	 * @param obj
     */
	function formatAmountOnFocus(obj){
		var value = $(obj).val();
		$(obj).val(value.replace(/,/g,""));
	}

	/**
	 * 失去焦点进行千分位展示
	 * @param obj
     */
	function formatAmountOnBlur(obj){
		var value = $(obj).val();
		if(!isSpace(value)){
			value = value.replace(/,/g,"");
			if ( !isNaN(value)){
				value=parseFloat(value);
				$(obj).val(formatMoney(value,2));
			}
		}
	}
	/**
	 * 失去焦点进行千分位展示
	 * @param obj
	 */
	function formatAmountOnBlurbeforePoint(obj){
		var value = $(obj).val();
		if(!isSpace(value)){
			value = value.replace(/,/g,"");
			if ( !isNaN(value)){
				//value=parseFloat(value);
				$(obj).val(formatMoneybeforePoint(value));
			}
		}
	}

	function validatePassword(s,memberNo,userMobile) {

		var allNumbers = /^\d+$/;  //全数字
		var allLetters = /^[A-Za-z]+$/;   //全字母
		var same3Numbers = /^\w*(000|111|222|333|444|555|666|777|888|999)+\w*$/;   //连续3个相同的数字
		var seq4Numbers = /^\w*(0123|1234|2345|3456|4567|5678|6789|9876|8765|7654|6543|5432|4321|3210)+\w*$/;   //连续4位的升序或者降序排列
		var onlyLetterAndNumber = /^[a-z0-9]+$/i;

		if(isSpace(s)){
			return "不能为空";
		}
		if(!onlyLetterAndNumber.test(s)){
			return "密码不能包含空格和特殊字符，只能由字母或数字组成";
		}
		if(s.length < 6 || s.length > 16){
			return "密码长度必须为6-16位";
		}
		if(allLetters.test(s)){
			return "密码不能全为字母";
		}
		if(same3Numbers.test(s)){
			return "密码不能同一个数字连续重复3次";
		}
		if(seq4Numbers.test(s)){
			return "密码不能出现连号的4个数字";
		}
		if(!isSpace(memberNo)){
			if(s == memberNo){
				return "不能使用会员编号作为密码";
			}
		}
		if(!isSpace(userMobile)){
			var pre = userMobile.substr(0,6);
			var sub = userMobile.substr(userMobile.length-6,6);
			if(s == pre || s == sub){
				return "不能使用用户手机号的前6位或后6位作为密码";
			}
		}
		// 两个数字不能连续重复三次   三个数字不能连续重复两次
		for(var i=0; i < s.length; i++){
			//依次取6位字符串
			var cur = s.substring(i,i+6);
			if(allNumbers.test(cur)){
				var cur2 = cur.substr(0,2);
				var loop2bit = cur2 + cur2 + cur2;

				var cur3 = cur.substr(0,3);
				var loop3bit = cur3 + cur3;

				if(cur == loop2bit){
					return "密码不可以两个数字连续重复了至少三次";
				}

				if(cur == loop3bit){
					return "密码不可以三个数字连续重复了至少两次";
				}
			}
		}
		return "";
	}

	function addCodeTip(option) {
		var defaults = {
			statu: 'success',
			phone: 'phone',
			target: $('#codeBtn'),
			idName: 'span_phone_code',
			msg: 'msg',
			wrap: ''
		}
		option = $.extend(defaults,option);
		var $item;
			option.wrap = option.wrap == '' ? option.target.parent() : option.wrap;
			option.wrap.find('.span_phone_code').remove();
			option.wrap.append('<div class="span_phone_code" id="'+option.idName+'"></div>');
			$item = option.wrap.find('#'+option.idName);
			$item.css({
				'margin-left': option.wrap.find('.control-label').width(),
				'width': option.msg.length * 14 +20
			});
			$item.text(option.msg);
		if (option.statu == 'success') {
			//$width = Math.abs(375- option.wrap.find('.form-control:first').outerWidth());
			$item.removeClass('error').addClass('success');
			//$item.text(option.msg);
		} else if (option.statu == 'error') {
			$item.removeClass('success').addClass('error');
			//$item.text(option.msg);
		}
	}

	function getMobiles(mobile){
		return mobile.substring(0,3)+"****"+mobile.substring(7,11);
	}

	function convertChnAmount(target,idName,type){
		//兼容IE8 IE11 必须使用这种写法
		target.bind('input propertychange', function() {
			target.parent().find('.span_phone_code').remove();
			var amt = target.val();
			if(!isSpace(amt)){
				amt = amt.replace(/,/g,"");
				if ( !isNaN(amt) && amt.indexOf("-")<0){
					amt=parseFloat(amt);
					var chnAmt = "";
					if(type == 1){
						chnAmt = tenThousandChineseNumber(amt);
					}else{
						chnAmt = chineseNumber(amt);
					}
					if(!isSpace(chnAmt)){
						target.parent().append('<div class="span_phone_code" id="'+idName+'"></div>');
						var $item = $("#"+idName);
						$item.text(chnAmt);
						$item.css({
							'width' : chnAmt.length * 12,
							'margin-left' : $("#regFund").parent().find('.control-label').width() + 5,
							'width' : chnAmt.length * 14 + 20,
							'margin-left' : $("#regFund").parent().find('.control-label').width() + 5,
							'padding': '0px 10px',
							'background': '#fff3eb none no-repeat 10px center',
							'line-height': '35px',
							'margin-top': '10px',
							'text-align': 'center',
							'font-size': '12px'
						})
					}
				}
			}
		});
	}

	function convertChineseAmount(target,idName,type){
		//兼容IE8 IE11 必须使用这种写法
			target.parent().find('.span_phone_code').remove();
			var amt = target.val();
			if(!isSpace(amt)){
				amt = amt.replace(/,/g,"");
				if ( !isNaN(amt) && amt.indexOf("-")<0){
					amt=parseFloat(amt);
					var chnAmt = "";
					if(type == 1){
						chnAmt = tenThousandChineseNumber(amt);
					}else{
						chnAmt = chineseNumber(amt);
					}
					if(!isSpace(chnAmt)){
						target.parent().append('<div class="span_phone_code" id="'+idName+'"></div>');
						var $item = $("#"+idName);
						$item.text(chnAmt);
						$item.css({
							'width': chnAmt.length * 14 + 20 ,
							'margin-left': target.parent().find('.control-label').width()+5
						})
					}
				}
			}
	}

	function globalTips(options) {
		var Default = {
			target: '', //绑定的元素  必填
			msg: '',    //你的提示消息  必填
			side: 1,  //提示窗显示位置  1，2，3，4 分别代表 上右下左 默认为1（上） 可选
			color: '#fff', //提示文字色 默认为白色 可选
			bg: '#ea5404',//提示窗背景色 默认为红色 可选
			time: 0,//自动关闭时间 默认2秒 设置0则不自动关闭 可选
			x: 0,//横向偏移  正数向右偏移 负数向左偏移 默认为0 可选
			y: 0,//纵向偏移  正数向下偏移 负数向上偏移 默认为0 可选
			w: 300,//tips宽度
			h: 30  //tips高度
		};
		options = $.extend(Default, options);

		options.target.hover(function() {
			$(options.target).tips({
				msg: options.msg,
				side: options.side,
				color: options.color,
				bg: options.bg,
				time: options.time,
				x: options.x,
				y: options.y,
				w: options.w,
				h: options.h
			});
		},function() {
			$("body").find('.jq_tips_box').remove();
		})
	}

	function globalPagination(pageTotal,rowSize,page_index,callbackF) {
		$("#Pagination").pagination(pageTotal, {
			'items_per_page': rowSize,   //显示条数
			'current_page': page_index,  //当前页索引
			'num_display_entries': 4,    //连续分页主体部分分页条目数
			'num_edge_entries': 1,       //两侧首尾分页条目数
			'prev_text': "上一页",        //上一页按钮里text
			'next_text': "下一页",        //下一页按钮里text
			'callback': callbackF        //回调函数
		});
		if (pageTotal > 0) {
			$('#totalPagination').empty();
			var paginationText = "共<span class='recordsTotal'> "+pageTotal+" </span>条记录，共<span class='pagesTotal'> "+Math.ceil(pageTotal/rowSize)+" </span>页";
			$('#totalPagination').html(paginationText);
		}else{
			$('#totalPagination').empty();
			$("#Pagination").empty();
		}
	}

	function globalNextPagination(pageTotal,rowSize,page_index,callbackF) {
		$("#nextPagination").pagination(pageTotal, {
			'items_per_page': rowSize,   //显示条数
			'current_page': page_index,  //当前页索引
			'num_display_entries': 4,    //连续分页主体部分分页条目数
			'num_edge_entries': 1,       //两侧首尾分页条目数
			'prev_text': "上一页",        //上一页按钮里text
			'next_text': "下一页",        //下一页按钮里text
			'callback': callbackF        //回调函数
		});
		if (pageTotal > 0) {
			$('#nextTotalPagination').empty();
			var paginationText = "共<span class='recordsTotal'> "+pageTotal+" </span>条记录，共<span class='pagesTotal'> "+Math.ceil(pageTotal/rowSize)+" </span>页";
			$('#nextTotalPagination').html(paginationText);
		}else{
			$('#nextTotalPagination').empty();
			$("#nextPagination").empty();
		}
	}

	function globalMorePagination(pageTotal,rowSize,page_index,callbackF,pagination,totalRows) {
		pagination.pagination(pageTotal, {
			'items_per_page': rowSize,   //显示条数
			'current_page': page_index,  //当前页索引
			'num_display_entries': 4,    //连续分页主体部分分页条目数
			'num_edge_entries': 1,       //两侧首尾分页条目数
			'prev_text': "上一页",        //上一页按钮里text
			'next_text': "下一页",        //下一页按钮里text
			'callback': callbackF        //回调函数
		});
		if (pageTotal > 0) {
			totalRows.empty();
			var paginationText = "共<span class='recordsTotal'> "+pageTotal+" </span>条记录，共<span class='pagesTotal'> "+Math.ceil(pageTotal/rowSize)+" </span>页";
			totalRows.html(paginationText);
		}else{
			totalRows.empty();
			pagination.empty();
		}
	}

	function globalEllipsis(num,text) {
		return text.substring(0,num)+"...";
	}

	function subString(str, len, hasDot) {
		var newLength = 0;
		var newStr = "";
		var chineseRegex = /[^\x00-\xff]/g;
		var singleChar = "";
		var strLength = str.replace(chineseRegex,"**").length;
		for(var i = 0;i < strLength;i++) {
			singleChar = str.charAt(i).toString();
			if(singleChar.match(chineseRegex) != null){
				newLength += 2;
			} else{
				newLength++;
			}
			if(newLength > len){
				break;
			}
			newStr += singleChar;
		}

		if(hasDot && strLength > len){
			newStr += "...";
		}
		return newStr;
	}


	function globalconvertUrl(url){
		//  var getTimestamp=Math.random();
		var getTimestamp=new Date().getTime();
		if(url.indexOf("?")>-1){
			url=url+"&t="+getTimestamp
		}else{
			url=url+"?t="+getTimestamp
		}
		return url;
	}

	/**
	 * 强大的数字千分位格式化
	 * @public
	 * @param mixed mVal 数值
	 * @param int iAccuracy 小数位精度(默认为2)
	 * @return string
	 */
	function newFormatMoney(mVal, iAccuracy,isPow){
		var fTmp = 0.00;//临时变量
		var iFra = 0;//小数部分
		var iInt = 0;//整数部分
		var aBuf = new Array(); //输出缓存
		var bPositive = true; //保存正负值标记(true:正数)
		/**
		 * 输出定长字符串，不够补0
		 * <li>闭包函数</li>
		 * @param int iVal 值
		 * @param int iLen 输出的长度
		 */
		function funZero(iVal, iLen){
			var sTmp = iVal.toString();
			var sBuf = new Array();
			for(var i=0,iLoop=iLen-sTmp.length; i<iLoop; i++)
				sBuf.push('0');
			sBuf.push(sTmp);
			return sBuf.join('');
		};

		if (typeof(iAccuracy) === 'undefined')
			iAccuracy = 2;
		bPositive = (mVal >= 0);//取出正负号
		fTmp = (isNaN(fTmp = parseFloat(mVal))) ? 0 : Math.abs(fTmp);//强制转换为绝对值数浮点
		//所有内容用正数规则处理
		iInt = parseInt(fTmp); //分离整数部分
		if(isPow){
			iFra = parseInt((fTmp - iInt) * Math.pow(10,iAccuracy) + 0.5); //分离小数部分(四舍五入)
			if(iFra.toString().length>iAccuracy){
				iInt = iInt + 1;
				iFra = parseInt(iFra.toString().substr(1));
			}
		}else{
			var tmp = mVal.toString().split(".").length==2?mVal.toString().split(".")[1]:0;
			if(tmp.length>=iAccuracy){
				iFra = parseInt(tmp.substr(0,iAccuracy));
			}else{
				var str = "";
				for(var i=0;i<iAccuracy-tmp.length;i++){
					str += "0";
				}
				iFra = parseInt(tmp + str);
			}
		}


		do{
			aBuf.unshift(funZero(iInt % 1000, 3));
		}while((iInt = parseInt(iInt/1000)));
		//aBuf[0] = parseInt(aBuf[0]).toString();//最高段区去掉前导0
		if(aBuf.length >= 1){
			if(aBuf[0].indexOf('0') == 0 && aBuf[0].length > 1){
				do{
					if(aBuf[0].length > 1){
						aBuf[0] = aBuf[0].substr(1);
					}
				}while(aBuf[0].indexOf('0') == 0 && aBuf[0].length > 1);
			}
		}
		return ((bPositive)?'':'-') + aBuf.join(',') +'.'+ ((0 === iFra)?'00':funZero(iFra, iAccuracy));
	}

	/**
	 * 将千分位格式的数字字符串转换为浮点数
	 * @public
	 * @param string sVal 数值字符串
	 * @return float
	 */
	function unformatMoney(sVal){
		var fTmp = parseFloat(sVal.replace(/,/g, ''));
		return (isNaN(fTmp) ? 0 : fTmp);
	}

	/**
	 * 组织机构代码校验
	 * @param val
	 * @returns {boolean}
     */
	function validateOrgCode(val){
		var ws = [3, 7, 9, 10, 5, 8, 4, 2];
		var str = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
		var reg = /^([0-9A-Z]){8}-[0-9|X]$/;
		if (!reg.test(val)) {
			alert("组织机构代码不合法！");
			return false;
		}
	}

	/**
	 * 获取字符串长度
	 * 三字节的中文替换为三个单字节再获取长度
	 * utf-8编码瞎汉字占3个字节
	 * @param str
	 * @returns {*}
     */
	function getStrLength(str) {
		if (str == null) return 0;
		if (typeof str != "string"){
			str += "";
		}
		return str.replace(/[\u4E00-\u9FA5\uF900-\uFA2D]/g,"012").length;
	}
